package org.pms.demo.webservice.controller;


import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;
import org.pms.demo.webservice.exception.IMReadException;
import org.pms.demo.webservice.service.ResourceVersionService;
import org.pms.demo.webservice.utils.ProjectUtils;
import org.pms.demo.webservice.vo.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.Path;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *
 */
@Component
@Path("/v{version}/user")
public class UserVersionRestController {
    @Resource
    private ResourceVersionService resourceVersionService;

    @GET
    @Path("/info")
    public String download(@HeaderParam("user-agent") String user_agent,@QueryParam("type")String type,
                           @Context HttpServletResponse responese, @Context HttpServletRequest request,
                           @QueryParam("channel")String channel, @QueryParam("os")String os,@HeaderParam("info-vcode")String vcode,
                           @HeaderParam("info-channel")String headerChanel,@HeaderParam("info-appid")String appid){
        try{
            Subject currentUser = SecurityUtils.getSubject();//获取当前用户
            Session session = currentUser.getSession();  //获取会话
            //currentUser.checkPermission("user:create");//检查是否有对应权限
            //currentUser.checkRole("管理员");//检查是否有对应角色
            // currentUser.logout(); //执行登出操作,移除对应的session以及权限数据。
            UserInfo userInfo = new UserInfo();
            userInfo.setName("admin");
            return ProjectUtils.getContentMsg(userInfo);
        }catch (Exception e){
            IMReadException.printf(e);
        }
        return ProjectUtils.getErrorMsg("error");
    }
    @GET
    @Path("/resource/list")
    public String getRseoureList(@HeaderParam("user-agent") String user_agent,@QueryParam("type")String type,
                           @Context HttpServletResponse responese, @Context HttpServletRequest request,
                           @QueryParam("channel")String channel, @QueryParam("os")String os,@HeaderParam("info-vcode")String vcode,
                           @HeaderParam("info-channel")String headerChanel,@HeaderParam("info-appid")String appid){

        try{
            return resourceVersionService.getResoureListByUser();
        }catch (Exception e){
            IMReadException.printf(e);
        }
        return ProjectUtils.getErrorMsg("error");

    }


    @GET
    @Path("/m/info")
    public String getMInfo(){

        return "123123123";
    }
}
